package com.ddz.qpz.controller.api;

import com.ddz.common.result.BaseResult;
import com.ddz.qpz.base.util.JwtUtils;
import com.ddz.qpz.pojo.vo.FundVo;
import com.ddz.qpz.pojo.vo.InvestVO;
import com.ddz.qpz.service.UserHoldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: LiQingBo
 * @Date: 2021/11/1-11-01-18:30
 * @Description: com.ddz.qpz.controller.api
 * @version: 1.0
 */
@Api(tags = "基金操作接口")
@RestController
@RequestMapping("/api/core/userHold")
@Slf4j
public class UserHoldController {
    @Resource
    private UserHoldService userHoldService;

    @ApiOperation("购买基金")
    @PostMapping("/buyFund")
    public BaseResult BuyFund(@RequestBody FundVo fundVo, HttpServletRequest request) {
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        String userName = JwtUtils.getUserName(token);
        fundVo.setInvestUserId(userId);
        fundVo.setInvestName(userName);
        String formStr = userHoldService.commitInvest(fundVo);
        return BaseResult.ok().data("formStr", formStr);
    }
}
